package com.example.scaletest;

import android.util.DisplayMetrics;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;


import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;

import java.util.List;

public class OutAdapter extends BaseQuickAdapter<IoEntity, BaseViewHolder> {

    private List<IoEntity> datas;

    public OutAdapter(int layoutResId, @Nullable List<IoEntity> data) {
        super(layoutResId, data);
        this.datas = data;
    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, IoEntity ioEntity) {
//        // 获取屏幕宽度
//        DisplayMetrics displayMetrics = helper.itemView.getContext().getResources().getDisplayMetrics();
//        int screenWidth = displayMetrics.widthPixels;
//
//        // 计算每个子项的宽度
//        int numberOfColumns = datas.size(); // 你想要的列数
//        int itemWidth = screenWidth / numberOfColumns;
//
//        // 设置子项的宽度
//        ViewGroup.LayoutParams layoutParams = helper.itemView.getLayoutParams();
//        layoutParams.width = itemWidth;
        helper.setText(R.id.tv_io_name, "名称：" + ioEntity.getName())
                .setText(R.id.tv_io_time, "延迟时间:" + ioEntity.getDelayTime())
                .setText(R.id.tv_io_switch, ioEntity.getVoltage() == 0 ? "关" : "开")
                ;
    }
}
